package org.jeecgframework.web.service.impl;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.web.service.CbsConditionServiceI;
import org.jeecgframework.web.system.pojo.base.CbsConditionEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;
import java.io.Serializable;

@Service("cbsConditionService")
@Transactional
public class CbsConditionServiceImpl extends CommonServiceImpl implements CbsConditionServiceI {

	
 	public <T> void delete(T entity) {
 		super.delete(entity);
 		//执行删除操作配置的sql增强
		this.doDelSql((CbsConditionEntity)entity);
 	}
 	
 	public <T> Serializable save(T entity) {
 		Serializable t = super.save(entity);
 		//执行新增操作配置的sql增强
 		this.doAddSql((CbsConditionEntity)entity);
 		return t;
 	}
 	
 	public <T> void saveOrUpdate(T entity) {
 		super.saveOrUpdate(entity);
 		//执行更新操作配置的sql增强
 		this.doUpdateSql((CbsConditionEntity)entity);
 	}
 	
 	/**
	 * 默认按钮-sql增强-新增操作
	 * @param id
	 * @return
	 */
 	public boolean doAddSql(CbsConditionEntity t){
	 	return true;
 	}
 	/**
	 * 默认按钮-sql增强-更新操作
	 * @param id
	 * @return
	 */
 	public boolean doUpdateSql(CbsConditionEntity t){
	 	return true;
 	}
 	/**
	 * 默认按钮-sql增强-删除操作
	 * @param id
	 * @return
	 */
 	public boolean doDelSql(CbsConditionEntity t){
	 	return true;
 	}

	@Override
	public List<CbsConditionEntity> getTermTree(String conditionParentId) {
		List<CbsConditionEntity> cbsConditionEntities = this.findByPropertyLike(CbsConditionEntity.class,"conditionParentId",conditionParentId);
		return cbsConditionEntities;
	}

	/**
	 * 替换sql中的变量
	 * @param sql
	 * @return
	 */
 	public String replaceVal(String sql,CbsConditionEntity t){
 		sql  = sql.replace("#{id}",String.valueOf(t.getId()));
 		sql  = sql.replace("#{conditioncode}",String.valueOf(t.getConditioncode()));
 		sql  = sql.replace("#{conditionname}",String.valueOf(t.getConditionname()));
 		sql  = sql.replace("#{condition_parent_id}",String.valueOf(t.getConditionParentId()));
 		sql  = sql.replace("#{include_symbol}",String.valueOf(t.getIncludeSymbol()));
 		sql  = sql.replace("#{mes_chinese}",String.valueOf(t.getMesChinese()));
 		sql  = sql.replace("#{UUID}",UUID.randomUUID().toString());
 		return sql;
 	}
}